home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / XAMPP 1.4.14 / xampp-win32-1.4.14-installer.exe / xampp / phpMyAdmin / server_status.php < prev    next >
PHP Script  |  2005-03-05  |  14KB  |  262 lines

  1. <?php
  2. /* $Id: server_status.php,v 2.12 2005/03/06 01:06:46 rabus Exp $ */
  3. // vim: expandtab sw=4 ts=4 sts=4:
  4.  
  5.  
  6. /**
  7.  * Does the common work
  8.  */
  9. require('./server_common.inc.php');
  10.  
  11.  
  12. /**
  13.  * Displays the links
  14.  */
  15. require('./server_links.inc.php');
  16.  
  17.  
  18. /**
  19.  * Displays the sub-page heading
  20.  */
  21. echo '<h2>' . "\n"
  22.    . ($GLOBALS['cfg']['MainPageIconic'] ? '<img src="' . $GLOBALS['pmaThemeImage'] . 's_status.png" width="16" height="16" border="0" hspace="2" align="middle" />' : '' )
  23.    . '    ' . $strServerStatus . "\n"
  24.    . '</h2>' . "\n";
  25.  
  26.  
  27. /**
  28.  * Checks if the user is allowed to do what he tries to...
  29.  */
  30. if (!$is_superuser && !$cfg['ShowMysqlInfo']) {
  31.     echo $strNoPrivileges;
  32.     require_once('./footer.inc.php');
  33. }
  34.  
  35.  
  36. /**
  37.  * Sends the query and buffers the result
  38.  */
  39. $res = PMA_DBI_query('SHOW STATUS;');
  40. while ($row = PMA_DBI_fetch_row($res)) {
  41.     $serverStatus[$row[0]] = $row[1];
  42. }
  43. PMA_DBI_free_result($res);
  44. unset($res, $row);
  45.  
  46.  
  47. /**
  48.  * Displays the page
  49.  */
  50. //Uptime calculation
  51. $res = PMA_DBI_query('SELECT UNIX_TIMESTAMP() - ' . $serverStatus['Uptime'] . ';');
  52. $row = PMA_DBI_fetch_row($res);
  53. echo sprintf($strServerStatusUptime, PMA_timespanFormat($serverStatus['Uptime']), PMA_localisedDate($row[0])) . "\n";
  54. PMA_DBI_free_result($res);
  55. unset($res, $row);
  56. //Get query statistics
  57. $queryStats = array();
  58. $tmp_array = $serverStatus;
  59. foreach ($tmp_array AS $name => $value) {
  60.     if (substr($name, 0, 4) == 'Com_') {
  61.         $queryStats[str_replace('_', ' ', substr($name, 4))] = $value;
  62.         unset($serverStatus[$name]);
  63.     }
  64. }
  65. unset($tmp_array);
  66. ?>
  67. <ul>
  68.     <li>
  69.         <!-- Server Traffic -->
  70.         <?php echo $strServerTrafficNotes; ?><br />
  71.         <table border="0" cellpadding="5" cellspacing="0">
  72.             <tr>
  73.                 <td valign="top">
  74.                     <table border="0" cellpadding="2" cellspacing="1">
  75.                         <tr>
  76.                             <th colspan="2"> <?php echo $strTraffic; ?> </th>
  77.                             <th> ø <?php echo $strPerHour; ?> </th>
  78.                         </tr>
  79.                         <tr>
  80.                             <td bgcolor="<?php echo $cfg['BgcolorTwo']; ?>"> <?php echo $strReceived; ?> </td>
  81.                             <td bgcolor="<?php echo $cfg['BgcolorTwo']; ?>" align="right"> <?php echo join(' ', PMA_formatByteDown($serverStatus['Bytes_received'])); ?> </td>
  82.                             <td bgcolor="<?php echo $cfg['BgcolorTwo']; ?>" align="right"> <?php echo join(' ', PMA_formatByteDown($serverStatus['Bytes_received'] * 3600 / $serverStatus['Uptime'])); ?> </td>
  83.                         </tr>
  84.                         <tr>
  85.                             <td bgcolor="<?php echo $cfg['BgcolorTwo']; ?>"> <?php echo $strSent; ?> </td>
  86.                             <td bgcolor="<?php echo $cfg['BgcolorTwo']; ?>" align="right"> <?php echo join(' ', PMA_formatByteDown($serverStatus['Bytes_sent'])); ?> </td>
  87.                             <td bgcolor="<?php echo $cfg['BgcolorTwo']; ?>" align="right"> <?php echo join(' ', PMA_formatByteDown($serverStatus['Bytes_sent'] * 3600 / $serverStatus['Uptime'])); ?> </td>
  88.                         </tr>
  89.                         <tr>
  90.                             <td bgcolor="<?php echo $cfg['BgcolorOne']; ?>"> <?php echo $strTotalUC; ?> </td>
  91.                             <td bgcolor="<?php echo $cfg['BgcolorOne']; ?>" align="right"> <?php echo join(' ', PMA_formatByteDown($serverStatus['Bytes_received'] + $serverStatus['Bytes_sent'])); ?> </td>
  92.                             <td bgcolor="<?php echo $cfg['BgcolorOne']; ?>" align="right"> <?php echo join(' ', PMA_formatByteDown(($serverStatus['Bytes_received'] + $serverStatus['Bytes_sent']) * 3600 / $serverStatus['Uptime'])); ?> </td>
  93.                         </tr>
  94.                     </table>
  95.                 </td>
  96.                 <td valign="top">
  97.                     <table border="0" cellpadding="2" cellspacing="1">
  98.                         <tr>
  99.                             <th colspan="2"> <?php echo $strConnections; ?> </th>
  100.                             <th> ø <?php echo $strPerHour; ?> </th>
  101.                             <th> % </th>
  102.                         </tr>
  103.                         <tr>
  104.                             <td bgcolor="<?php echo $cfg['BgcolorTwo']; ?>"> <?php echo $strFailedAttempts; ?> </td>
  105.                             <td bgcolor="<?php echo $cfg['BgcolorTwo']; ?>" align="right"> <?php echo number_format($serverStatus['Aborted_connects'], 0, $number_decimal_separator, $number_thousands_separator); ?> </td>
  106.                             <td bgcolor="<?php echo $cfg['BgcolorTwo']; ?>" align="right"> <?php echo number_format(($serverStatus['Aborted_connects'] * 3600 / $serverStatus['Uptime']), 2, $number_decimal_separator, $number_thousands_separator); ?> </td>
  107.                             <td bgcolor="<?php echo $cfg['BgcolorTwo']; ?>" align="right"> <?php echo ($serverStatus['Connections'] > 0 ) ? number_format(($serverStatus['Aborted_connects'] * 100 / $serverStatus['Connections']), 2, $number_decimal_separator, $number_thousands_separator) . ' %' : '---'; ?> </td>
  108.                         </tr>
  109.                         <tr>
  110.                             <td bgcolor="<?php echo $cfg['BgcolorTwo']; ?>"> <?php echo $strAbortedClients; ?> </td>
  111.                             <td bgcolor="<?php echo $cfg['BgcolorTwo']; ?>" align="right"> <?php echo number_format($serverStatus['Aborted_clients'], 0, $number_decimal_separator, $number_thousands_separator); ?> </td>
  112.                             <td bgcolor="<?php echo $cfg['BgcolorTwo']; ?>" align="right"> <?php echo number_format(($serverStatus['Aborted_clients'] * 3600 / $serverStatus['Uptime']), 2, $number_decimal_separator, $number_thousands_separator); ?> </td>
  113.                             <td bgcolor="<?php echo $cfg['BgcolorTwo']; ?>" align="right"> <?php echo ($serverStatus['Connections'] > 0 ) ? number_format(($serverStatus['Aborted_clients'] * 100 / $serverStatus['Connections']), 2 , $number_decimal_separator, $number_thousands_separator) . ' %' : '---'; ?> </td>
  114.                         </tr>
  115.                         <tr>
  116.                             <td bgcolor="<?php echo $cfg['BgcolorOne']; ?>"> <?php echo $strTotalUC; ?> </td>
  117.                             <td bgcolor="<?php echo $cfg['BgcolorOne']; ?>" align="right"> <?php echo number_format($serverStatus['Connections'], 0, $number_decimal_separator, $number_thousands_separator); ?> </td>
  118.                             <td bgcolor="<?php echo $cfg['BgcolorOne']; ?>" align="right"> <?php echo number_format(($serverStatus['Connections'] * 3600 / $serverStatus['Uptime']), 2, $number_decimal_separator, $number_thousands_separator); ?> </td>
  119.                             <td bgcolor="<?php echo $cfg['BgcolorOne']; ?>" align="right"> <?php echo number_format(100, 2, $number_decimal_separator, $number_thousands_separator); ?> % </td>
  120.                         </tr>
  121.                     </table>
  122.                 </td>
  123.             </tr>
  124.         </table>
  125.     </li>
  126.     <li>
  127.         <!-- Queries -->
  128.         <?php echo sprintf($strQueryStatistics, number_format($serverStatus['Questions'], 0, $number_decimal_separator, $number_thousands_separator)) . "\n"; ?>
  129.         <table border="0" cellpadding="5" cellspacing="0">
  130.             <tr>
  131.                 <td colspan="2">
  132.                     <table border="0" cellpadding="2" cellspacing="1" width="100%">
  133.                         <tr>
  134.                             <th> <?php echo $strTotalUC; ?> </th>
  135.                             <th> ø <?php echo $strPerHour; ?> </th>
  136.                             <th> ø <?php echo $strPerMinute; ?> </th>
  137.                             <th> ø <?php echo $strPerSecond; ?> </th>
  138.                         </tr>
  139.                         <tr>
  140.                             <td bgcolor="<?php echo $cfg['BgcolorOne']; ?>" align="right"> <?php echo number_format($serverStatus['Questions'], 0, $number_decimal_separator, $number_thousands_separator); ?> </td>
  141.                             <td bgcolor="<?php echo $cfg['BgcolorOne']; ?>" align="right"> <?php echo number_format(($serverStatus['Questions'] * 3600 / $serverStatus['Uptime']), 2, $number_decimal_separator, $number_thousands_separator); ?> </td>
  142.                             <td bgcolor="<?php echo $cfg['BgcolorOne']; ?>" align="right"> <?php echo number_format(($serverStatus['Questions'] * 60 / $serverStatus['Uptime']), 2, $number_decimal_separator, $number_thousands_separator); ?> </td>
  143.                             <td bgcolor="<?php echo $cfg['BgcolorOne']; ?>" align="right"> <?php echo number_format(($serverStatus['Questions'] / $serverStatus['Uptime']), 2, $number_decimal_separator, $number_thousands_separator); ?> </td>
  144.                         </tr>
  145.                     </table>
  146.                 </td>
  147.             </tr>
  148.             <tr>
  149.                 <td valign="top">
  150.                     <table border="0" cellpadding="2" cellspacing="1">
  151.                         <tr>
  152.                             <th colspan="2"> <?php echo $strQueryType; ?> </th>
  153.                             <th> ø <?php echo $strPerHour; ?> </th>
  154.                             <th> % </th>
  155.                         </tr>
  156. <?php
  157.  
  158. $useBgcolorOne = TRUE;
  159. $countRows = 0;
  160. foreach ($queryStats as $name => $value) {
  161.  
  162. // For the percentage column, use Questions - Connections, because
  163. // the number of connections is not an item of the Query types
  164. // but is included in Questions. Then the total of the percentages is 100.
  165. ?>
  166.                         <tr>
  167.                             <td bgcolor="<?php echo $useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']; ?>"> <?php echo htmlspecialchars($name); ?> </td>
  168.                             <td bgcolor="<?php echo $useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']; ?>" align="right"> <?php echo number_format($value, 0, $number_decimal_separator, $number_thousands_separator); ?> </td>
  169.                             <td bgcolor="<?php echo $useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']; ?>" align="right"> <?php echo number_format(($value * 3600 / $serverStatus['Uptime']), 2, $number_decimal_separator, $number_thousands_separator); ?> </td>
  170.                             <td bgcolor="<?php echo $useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']; ?>" align="right"> <?php echo number_format(($value * 100 / ($serverStatus['Questions'] - $serverStatus['Connections'])), 2, $number_decimal_separator, $number_thousands_separator); ?> % </td>
  171.                         </tr>
  172. <?php
  173.     $useBgcolorOne = !$useBgcolorOne;
  174.     if (++$countRows == ceil(count($queryStats) / 2)) {
  175.         $useBgcolorOne = TRUE;
  176. ?>
  177.                     </table>
  178.                 </td>
  179.                 <td valign="top">
  180.                     <table border="0" cellpadding="2" cellspacing="1">
  181.                         <tr>
  182.                             <th colspan="2"> <?php echo $strQueryType; ?> </th>
  183.                             <th> ø <?php echo $strPerHour; ?> </th>
  184.                             <th> % </th>
  185.                         </tr>
  186. <?php
  187.     }
  188. }
  189. unset($countRows);
  190. unset($useBgcolorOne);
  191. ?>
  192.                     </table>
  193.                 </td>
  194.             </tr>
  195.         </table>
  196.     </li>
  197. <?php
  198. //Unset used variables
  199. unset($serverStatus['Aborted_clients']);
  200. unset($serverStatus['Aborted_connects']);
  201. unset($serverStatus['Bytes_received']);
  202. unset($serverStatus['Bytes_sent']);
  203. unset($serverStatus['Connections']);
  204. unset($serverStatus['Questions']);
  205. unset($serverStatus['Uptime']);
  206.  
  207. if (!empty($serverStatus)) {
  208. ?>
  209.     <li>
  210.         <!-- Other status variables -->
  211.         <b><?php echo $strMoreStatusVars; ?></b><br />
  212.         <table border="0" cellpadding="5" cellspacing="0">
  213.             <tr>
  214.                 <td valign="top">
  215.                     <table border="0" cellpadding="2" cellspacing="1">
  216.                         <tr>
  217.                             <th> <?php echo $strVar; ?> </th>
  218.                             <th> <?php echo $strValue; ?> </th>
  219.                         </tr>
  220. <?php
  221.     $useBgcolorOne = TRUE;
  222.     $countRows = 0;
  223.     foreach ($serverStatus AS $name => $value) {
  224. ?>
  225.                         <tr>
  226.                             <td bgcolor="<?php echo $useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']; ?>"> <?php echo htmlspecialchars(str_replace('_', ' ', $name)); ?> </td>
  227.                             <td bgcolor="<?php echo $useBgcolorOne ? $cfg['BgcolorOne'] : $cfg['BgcolorTwo']; ?>" align="right"> <?php echo htmlspecialchars($value); ?> </td>
  228.                         </tr>
  229. <?php
  230.         $useBgcolorOne = !$useBgcolorOne;
  231.         if (++$countRows == ceil(count($serverStatus) / 3) || $countRows == ceil(count($serverStatus) * 2 / 3)) {
  232.             $useBgcolorOne = TRUE;
  233. ?>
  234.                     </table>
  235.                 </td>
  236.                 <td valign="top">
  237.                     <table border="0" cellpadding="2" cellspacing="1">
  238.                         <tr>
  239.                             <th> <?php echo $strVar; ?> </th>
  240.                             <th> <?php echo $strValue; ?> </th>
  241.                         </tr>
  242. <?php
  243.         }
  244.     }
  245.     unset($useBgcolorOne);
  246. ?>
  247.                     </table>
  248.                 </td>
  249.             </tr>
  250.         </table>
  251.     </li>
  252. <?php
  253. }
  254.  
  255.  
  256. /**
  257.  * Sends the footer
  258.  */
  259. require_once('./footer.inc.php');
  260.  
  261. ?>
  262.